package com.shbaiche.bifenba.adapter.my;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.user.FollowInfoVo;
import com.shbaiche.bifenba.view.CircularImage;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;

/**
 * Created by wanglei on 2016/12/10.
 */

public class TeamListAdapter extends SimpleRecAdapter<FollowInfoVo, TeamListAdapter.ViewHolder> {

    public interface TeamListCallBack {
        public void cancel(FollowInfoVo item,int pos);
    }

    private TeamListCallBack listener;

    public TeamListAdapter(Context context, TeamListCallBack listener) {
        super(context);
        this.listener = listener;
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_team_list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final FollowInfoVo item = data.get(position);

        //ILFactory.getLoader().loadNet(holder.ivGirl, item.getUrl(), null);
        holder.tvName.setText(item.getName() + "");
        Glide.with(context).load(item.getLogo()).placeholder(R.drawable.ic_my_head).error(R.drawable.ic_my_head).into(holder.ivLogo);

        if (item.getIsFollow().getValue()) {
            holder.btnFollow.setText("已关注");
            holder.btnFollow.setTextColor(Color.parseColor("#2479E2"));
            holder.btnFollow.setShapeStrokeColor(Color.parseColor("#2479E2"));

        } else {
            holder.btnFollow.setText("未关注");
            holder.btnFollow.setTextColor(Color.parseColor("#969BA3"));
            holder.btnFollow.setShapeStrokeColor(Color.parseColor("#969BA3"));
        }

        holder.btnFollow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.cancel(item,position);
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_logo)
        CircularImage ivLogo;

        @BindView(R.id.tv_name)
        TextView tvName;

        @BindView(R.id.sbt_follow)
        SuperButton btnFollow;


        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
